import os
import asyncio

case_idx = 0
input_root = '/home/imvision/hy/TrackNetV3-main/select_views_focus_center'
dst_root = '2d_tracknet_det'
view_select = [0, 1, 2, 17, 18, 19, 34, 35]

async def predict_2d(view):
    input_v = os.path.join(input_root, f"case_{case_idx}_v_{view}.mp4")
    cmd = f"python predict.py --video_file {input_v}"
    result = os.system(cmd)
    return result 
    #process = await asyncio.create_subprocess_shell(
    #   f'python predict.py --video_file {input_v}',
    #   stdout=asyncio.subprocess.PIPE,
    #   stderr=asyncio.subprocess.PIPE
    #)
    #print("子进程已启动，主程序不会阻塞...")
    #
    ## 等待子进程完成并获取输出
    #stdout, stderr = await process.communicate()
    #if stdout:
    #    print(f"子进程输出: {stdout.decode()}")
    #if stderr:
    #    print(f"子进程错误: {stderr.decode()}")

async def main():
    tasks = [asyncio.create_task(predict_2d(v)) for v in view_select]
    results = await asyncio.gather(*tasks)
    for result in results:
        print(f"收到: {result}")

asyncio.run(main())

